package com.duowan.realtime.server.util;

import org.codehaus.plexus.util.StringUtils;

import com.duowan.datawarehouse.util.NetUtil;
import com.duowan.realtime.webservice.DataComputingWebService;

public class BeanFactory {
	//http://data.computing.ws.game.yy.com/rpc/DataComputingWebService
	private static final String DWWS_MONITOR_URL = "http://data.computing.ws.game.yy.com/monitor.jsp";
	private static final String DWWS2_MONITOR_URL = "http://data.computing.ws.game.yy.com/monitor.jsp";

	public static DataComputingWebService getComputingWebService() {
		return (DataComputingWebService) getBean("dataComputingWebService");
	}


	private static Object getBean(String beanName) {
		if (isWebServiceHealth(DWWS_MONITOR_URL)) {
			return SpringContextFactory.getApplicationContext().getBean(beanName);
		}
	
		throw new RuntimeException("dwws不可用!,地址为dwws=" + DWWS_MONITOR_URL) ;
	}

	private static boolean isWebServiceHealth(String monitorUrl) {
		String monitorResponse = NetUtil.readURL(monitorUrl);
		return StringUtils.equals("200", StringUtils.trim(monitorResponse));
		// LOGGER.error("检测monitorUrl=" + monitorUrl + " ,异常!", e);
		// return false ;
	}
	

}
